// program/pages/index/index.js
const app = getApp();
const service = require('../../utils/service.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    key: 'MDQBZ-CNRRK-O6LJA-ALUQ5-ES67V-6PFWT',
    btnHeight: 32,
    statusHeight: 20,
    navHeight: 48,
    boxY: 0,
    move: 0,

    banner: [],
    // 菜单列表
    Menu: [],
    menuIdx: 0,

    // 地图实例
    mapContext: null,
    // 地图是否显示
    mapVisible: false,
    // 当前地图中心点经纬度
    // 精度
    latitude: '',
    // 纬度
    longitude: '',
    // 地点
    location: '',
    // 当前地址
    address: '',
    // 标记点
    markers: [],
    // 选择的地点
    chooseLocation: {},

    // 當前日期
    nowDate: app.utils.parseTime(new Date(), '{y}-{m}-{d}'),
    // 當前時間
    nowTime: '00:00',
    // 预定日期
    date: null,
    // 预定时间
    time: null,
    //  机场接送
    airportData: {
      // 接送机类型
      airportType: 0,
      // 选择的机场
      airportIdx: '',
    },
    // 专车
    specialData: {
      // 终点
      addressToName: null,
      // 终点详细地址
      addressTo: null,
      // 精度
      addressToLatitude: '',
      // 纬度
      addressToLongitude: '',
    },
    // 巴士
    dailyData: {
      // 出发点列表
      goData: [],
      // 目的地列表
      destinationDate: [],
      // picker默认出发地列表
      startSpotList: [],
      startSpotListPreview: [],
      // picker默认目的地列表
      endSpotList: [],
      endSpotListPreview: [],
      // 选择的出发点
      startSpot: [],
      // 选择的目的地
      endSpot: [],
    },
    // 包车
    fixedData: {
      // 出发点列表
      goData: [],
      // 目的地列表
      destinationDate: [],
      // picker默认出发地列表
      startSpotList: [],
      startSpotListPreview: [],
      // picker默认目的地列表
      endSpotList: [],
      endSpotListPreview: [],
      // 选择的出发点
      startSpot: [],
      // 选择的目的地
      endSpot: [],
    },
    // 优惠券信息
    couponInfo: {},

    // 时间选择插件
    isShow: false, // 默认不显示插件
    themeColor: '#ffd00a',
    calendarType: 'yydates',

    // 租车
    rentCar: {
      isShowToFormItem: false,
      beginDate: '',
      beginTime: '',
      beginTimeDay: '',
      endDate: '',
      endTime: '',
      endTimeDay: '',
      dayCount: 3,
      // 终点
      addressToName: null,
      // 终点详细地址
      addressTo: null,
      // 精度
      addressToLatitude: '',
      // 纬度
      addressToLongitude: '',
    }
  },

  // 优惠券相关=============================================
  // 获取优惠券信息
  loadCouponInfo() {
    let that = this;
    service.getConnect(service.api.getRegisterCouponInfo).then(function (res) {
      if (res.data) {
        let couponInfo = res.data;
        if (res.data.condition === '1') {
          couponInfo.condition = '新用户注册';
        } else if (res.data.condition === '2') {
          couponInfo.condition = '单笔订单金额满' + res.data.content + '元可使用';
        } else if (res.data.condition === '3') {
          couponInfo.condition = '指定用户可用';
        } else {
          couponInfo.condition = '无限制';
        }
        couponInfo.condition = couponInfo.condition + ', 有效期为' + res.data.timeFrom + '至' + res.data.timeTo;
        that.setData({
          couponInfo: couponInfo
        })
        that.couponDialog.showLoginDialog();
      }
    })
  },

  // 领取优惠券
  receiveCoupon() {
    let that = this;
    service.getConnect(service.api.receiveCoupon, {
      id: this.data.couponInfo['id']
    }).then(function (res) {
      wx.showToast({
        title: '领取成功~',
      })
      that.couponDialog.hideLoginDialog();
    })
  },

  // 地图相关===============================================
  regionchange(e) {
    console.log(e)
    this.getMapCenterLocation();
  },
  // 获取当前地图中心点经纬度
  getMapCenterLocation() {
    let that = this;
    this.data.mapContext.getCenterLocation({
      success(e) {
        that.setData(e);
        that.getAddress();
      }
    })
  },
  // 根据经纬度获取地址信息
  getAddress() {
    let that = this;
    let params = {
      latitude: this.data.latitude,
      longitude: this.data.longitude
    }
    service.getConnect(service.api.getAddressByLongitudeAndLatitude, params).then(res => {
      if (!res.data) {
        this.getAddress();
        wx.hideLoading();
        return;
      }
      that.setData({
        'location': res.data.formatted_addresses.recommend,
        'address': res.data.address
      })
      wx.hideLoading();
    })
  },

  toChooseLocation() {
    let that = this;
    wx.chooseLocation({
      success: res => {
        console.log(res)
        that.setData({
          'location': res.name,
          'address': res.address,
          'latitude': res.latitude,
          'longitude': res.longitude
        });
      }
    })
  },

  // 获取菜单信息================================================
  loadRouteHomepageData() {
    let that = this;
    service.getConnect(service.api.getRouteHomepageData).then(res => {
      // 获取banner返回值
      let banner = res.data['banner'];
      if (banner.length === 0) {
        banner = that.data.banner;
      }
      // 获取menu返回值
      let menu = res.data['Menu'];
      if (menu.length === 0) {
        menu = that.data.Menu;
      }
      that.setData({
        banner: banner,
        Menu: menu
      })
      wx.hideLoading();
    })
  },
  // 菜单点击
  bindTabItemClick(e) {
    if (this.data.Menu[e.currentTarget.dataset.idx].url !== 'pages/route/special/special' &&
      this.data.Menu[e.currentTarget.dataset.idx].url !== 'pages/route/airport/airport' &&
      this.data.Menu[e.currentTarget.dataset.idx].url !== 'pages/route/daily/index/index' &&
      this.data.Menu[e.currentTarget.dataset.idx].url !== 'pages/route/fixed/index/index' &&
      this.data.Menu[e.currentTarget.dataset.idx].url !== 'pages/rentCar/rentCar'
    ) {
      wx.navigateTo({
        url: '/' + this.data.Menu[e.currentTarget.dataset.idx].url,
      })
    } else {
      this.setData({
        menuIdx: e.currentTarget.dataset.idx
      })
    }
  },

  // 立即预定=========================================================
  bindToDetails() {
    if (this.data.Menu[this.data.menuIdx].url === 'pages/route/airport/airport') {
      if (!this.data.date) {
        // app.showConfirm('提示', '请选择接送时间', false);
        wx.showToast({
          title: '请选择接送时间',
          icon: "none"
        });
        return;
      }
      if (!this.data.airportData['airportIdx']) {
        // app.showConfirm('提示', '请选择接送机场', false);
        wx.showToast({
          title: '请选择接送机场',
          icon: "none"
        });
        return;
      }
      this.loadCarListAndPriceByParams();
    }
    if (this.data.Menu[this.data.menuIdx].url === 'pages/route/daily/index/index') {
      if (!this.data.date) {
        wx.showToast({
          title: '请选择预约时间',
          icon: "none"
        });
        return;
      }
      if (this.data.dailyData['endSpotList'].length === 0) {
        wx.showToast({
          title: '请选择出发地，目的地',
          icon: "none"
        });
        return;
      }
      this.bindDailySearch();
    }
    if (this.data.Menu[this.data.menuIdx].url === 'pages/route/special/special') {
      if (!this.data.date) {
        wx.showToast({
          title: '请选择预约时间',
          icon: "none"
        });
        return;
      }
      if (!this.data.specialData['addressTo']) {
        wx.showToast({
          title: '请选择目的地',
          icon: "none"
        });
        return;
      }
      this.loadSpecialCarListAndPriceByParams();
    }
    if (this.data.Menu[this.data.menuIdx].url === 'pages/route/fixed/index/index') {
      if (!this.data.date) {
        wx.showToast({
          title: '请选择预约时间',
          icon: "none"
        });
        return;
      }
      if (this.data.fixedData['endSpotList'].length === 0) {
        wx.showToast({
          title: '请选择出发地，目的地',
          icon: "none"
        });
        return;
      }
      this.bindFixedSearch();
    }
    if (this.data.Menu[this.data.menuIdx].url === 'pages/rentCar/rentCar') {
      if (!this.data.rentCar.beginTime||!this.data.rentCar.endTime) {
        wx.showToast({
          title: '请选择租车时间',
          icon: "none"
        });
        return;
      }
      if (!this.data.location) {
        wx.showToast({
          title: '请选择取车地',
          icon: "none"
        });
        return;
      }
      let rentCar = this.data.rentCar;
      rentCar.addressFromName = this.data.location;
      rentCar.addressFrom = this.data.address;
      rentCar.addressFromLatitude = this.data.latitude;
      rentCar.addressFromLongitude = this.data.longitude;
      wx.navigateTo({
        url: '/pages/rentCar/rentCar?rentCar='+JSON.stringify(rentCar)
      })
    }
  },

  // 日期选择=====================================================
  bindAirportDateChange(e) {
    this.setData({
      date: e.detail.value
    });
    if (e.detail.value === this.data.nowDate) {
      this.setData({
        nowTime: app.utils.parseTime(new Date(), '{h}:{i}')
      })
    }
  },
  // 时间选择
  bindAirportTimeChange(e) {
    this.setData({
      time: e.detail.value
    });
  },

  // 机场接送====================================================
  // 接送机选择
  bindAirportTypeClick(e) {
    this.setData({
      ['airportData.airportType']: e.currentTarget.dataset.type,
      ['airportData.airportIdx']: ''
    })
    this.loadAirportData();
  },
  // 加载机场信息
  loadAirportData() {
    let that = this;
    let params = {
      type: this.data.airportData['airportType'] + 1
    }
    service.getConnect(service.api.getAirportRouteData, params).then(function (res) {
      wx.hideLoading();
      that.setData(res.data);
    });
  },
  // 机场选择
  bindAirportChange(e) {
    this.setData({
      ['airportData.airportIdx']: e.detail.value
    })
  },
  // 根据地址信息获取车辆类型及价格
  loadCarListAndPriceByParams() {
    let that = this;
    if (this.data.airportData['airportIdx'] !== null && this.data.airportData['locatiion'] !== '' &&
      this.data.date !== null) {
      let params = {
        lineId: this.data['airport'][this.data.airportData['airportIdx']]['lineId'],
        address: this.data.address,
        latitude: this.data.latitude,
        longitude: this.data.longitude,
        chooseTime: this.data['date']
      }
      service.getConnect(service.api.getAirportRouteCarAndPrice, params).then(function (res) {
        params.navIdx = that.data.airportType;
        params.location = that.data.location;
        params.date = that.data['date'];
        params.time = that.data['time'];
        params.airportIdx = that.data.airportData['airportIdx'];
        wx.navigateTo({
          url: '/pages/route/airport/airport?params=' + JSON.stringify(params) + '&pageName=' + that.data.Menu[that.data.menuIdx].title,
        })
      });
    }
  },

  // 巴士相关===================================================
  loadDailyData() {
    let that = this;
    service.getConnect(service.api.getDailyRouteIndexData).then(function (res) {
      let temp = Object.assign({}, res.data);
      let startSpotList = [];
      if (temp.goData.length > 0) {
        startSpotList.push(temp.goData);
        startSpotList.push(temp.goData[0]['children']);
        startSpotList.push(temp.goData[0]['children'][0]['children'] || []);
      }
      let dailyData = {
        goData: temp.goData,
        destinationDate: temp.destinationDate,
        startSpotList: startSpotList,
        startSpotListPreview: startSpotList,
        endSpotList: [],
        endSpotListPreview: [],
        startSpot: [],
        endSpot: [],
        hotLineData: temp.hotLineData
      }
      that.setData({
        dailyData: dailyData
      });
      wx.hideLoading();
    })
  },
  // 选择地点
  bindSpotPickerChange(e) {
    // 类型,出发地还是目的地
    const type = e.currentTarget.dataset.type;
    // 出发地或目的地的列表
    const addressList = type + 'List';
    // 選擇的值
    let chooseData = e.detail.value;
    // 没改变的列默认会传null回来所以要转成0
    for (let i = 0; i < e.detail.value.length; i++) {
      if (chooseData[i] === null) {
        chooseData[i] = 0;
      }
    }
    // 因为picker显示的是一个长度为3的数组,对应3列,第2,3列会随着改变,所以需要保存一个当前选择的数组,才不会数据错乱
    let dailyData = Object.assign(this.data.dailyData, {
      [type]: chooseData,
      [addressList]: this.data.dailyData[addressList + 'Preview']
    })
    this.setData({
      dailyData: dailyData
    })
    // 当改变的是出发地时,对应修改目的地的列表
    if (type === 'startSpot') {
      // 从目的地列表中找到出发地对应的目的地列表
      let temp = this.data.dailyData['destinationDate'][this.data.dailyData['goData'][this.data.dailyData['startSpot'][0]]['code']];
      let endSpotList = [];
      if (temp.length > 0) {
        endSpotList.push(temp);
        endSpotList.push(temp[0]['children']);
        endSpotList.push(temp[0]['children'][0]['children'] || []);
      }
      dailyData = Object.assign(this.data.dailyData, {
        endSpotList: endSpotList,
        endSpotListPreview: endSpotList,
        endSpot: []
      })
      this.setData({
        dailyData: dailyData
      })
    }
  },
  // 列变化时
  bindSpotPickerColumnChange(e) {
    const value = e.currentTarget.dataset.type;
    const type = e.currentTarget.dataset.type + 'Preview';
    const addressList = e.currentTarget.dataset.type + 'ListPreview'
    const data = {
      [addressList]: this.data.dailyData[addressList],
      [type]: this.data.dailyData[value].length !== 0 ? this.data.dailyData[value] : [0, 0, 0]
    }
    data[type][e.detail.column] = e.detail.value;
    if (e.detail.column === 0) {
      data[addressList][1] = data[addressList][0][e.detail.value]['children'];
      data[addressList][2] = data[addressList][1][0]['children'] || [];
      data[type][1] = 0;
      data[type][2] = 0;
    } else if (e.detail.column === 1) {
      data[addressList][2] = data[addressList][1][e.detail.value]['children'] || [];
      data[type][2] = 0;
    }
    let dailyData = Object.assign(this.data.dailyData, {
      [addressList]: data[addressList],
      [type]: data[type]
    })
    this.setData({
      dailyData: dailyData
    })
  },
  // 点击目的地
  bindEndPickerTap(e) {
    if (this.data.dailyData.endSpotList.length === 0) {
      wx.showToast({
        icon: 'none',
        title: '请先选择出发地',
      })
    }
  },
  // 搜索
  bindDailySearch() {
    let lineId = null;
    let startSpotLineId = (this.data.dailyData['startSpotList'][2].length === 0 ?
      this.data.dailyData['startSpotList'][1][this.data.dailyData['startSpot'][1]]['lineId'] :
      this.data.dailyData['startSpotList'][2][this.data.dailyData['startSpot'][2]]['lineId']);
    startSpotLineId = (startSpotLineId + '').split(',');

    let endSpotLineId = (this.data.dailyData['endSpotList'][2].length === 0 ?
      this.data.dailyData['endSpotList'][1][this.data.dailyData['endSpot'][1]]['lineId'] :
      this.data.dailyData['endSpotList'][2][this.data.dailyData['endSpot'][2]]['lineId']);

    endSpotLineId = (endSpotLineId + '').split(',');

    lineId = endSpotLineId.filter(function (v) {
      return startSpotLineId.indexOf(v) !== -1 // 利用filter方法来遍历是否有相同的元素
    })

    lineId.join(',');

    if (lineId === null) {
      wx.showToast({
        title: '路线不存在，请重新选择~',
        icon: "none"
      })
      return;
    }

    wx.navigateTo({
      url: '/pages/route/daily/timetable/timetable?lineId=' + lineId + '&chooseTime=' + this.data['date'] + '&pageName=' + this.data.Menu[this.data.menuIdx].title,
    })
  },

  // 专车相关====================================================
  // 加载信息
  loadSpecialData() {
    let that = this;
    service.getConnect(service.api.getSpecialRouteData).then(function (res) {
      wx.hideLoading();
      that.setData({
        specialData: res.data
      });
    });
  },
  // 选择目的地点
  bindSelectAddressTo(e) {
    var that = this;
    wx.chooseLocation({
      success: res => {
        that.setData({
          specialData: {
            addressToName: res.name,
            addressTo: res.address,
            addressToLatitude: res.latitude,
            addressToLongitude: res.longitude
          }
        });
      }
    })
  },
  // 根据地址信息获取车辆类型及价格
  loadSpecialCarListAndPriceByParams() {
    let that = this;
    if (this.data['address'] !== '' && this.data.specialData['addressTo'] !== '' &&
      this.data['date'] !== null) {
      let params = {
        addressFrom: this.data['address'],
        addressTo: this.data['addressTo'],
        addressFromLatitude: this.data.latitude,
        addressFromLongitude: this.data.longitude,
        addressToLatitude: this.data.specialData.addressToLatitude,
        addressToLongitude: this.data.specialData.addressToLongitude,
        chooseTime: this.data['date']
      }
      service.getConnect(service.api.getSpecialRouteCarAndPrice, params).then(function (res) {
        wx.hideLoading();
        let temp = {
          // 起点
          addressFromName: that.data.location,
          // 起点详细地址
          addressFrom: that.data.address,
          // 精度
          addressFromLatitude: that.data.latitude,
          // 纬度
          addressFromLongitude: that.data.longitude,
          date: that.data.date,
          time: that.data.time
        }

        wx.navigateTo({
          url: '/pages/route/special/special?params=' + JSON.stringify(Object.assign(temp, that.data.specialData)) + '&pageName=' + that.data.Menu[that.data.menuIdx].title,
        })
      });
    }
  },

  // 包车========================================================
  // 加载首页数据
  loadFixedData() {
    let that = this;
    service.getConnect(service.api.getFixedRouteIndexData).then(function (res) {
      wx.hideLoading();
      let temp = Object.assign({}, res.data);
      let startSpotList = [];
      if (temp.goData.length > 0) {
        startSpotList.push(temp.goData);
        startSpotList.push(temp.goData[0]['children']);
        startSpotList.push(temp.goData[0]['children'][0]['children'] || []);
      }
      let fixedData = {
        goData: temp.goData,
        destinationDate: temp.destinationDate,
        startSpotList: startSpotList,
        startSpotListPreview: startSpotList,
        endSpotList: [],
        endSpotListPreview: [],
        startSpot: [],
        endSpot: [],
        hotLineData: temp.hotLineData
      }
      that.setData({
        fixedData: fixedData
      });
    })
  },
  // 点击目的地
  bindFixedEndPickerTap(e) {
    if (this.data.fixedData.endSpotList.length === 0) {
      wx.showToast({
        icon: "none",
        title: '请先选择出发地',
      })
    }
  },
  // 选择地点
  bindFixedSpotPickerChange(e) {
    // 类型,出发地还是目的地
    const type = e.currentTarget.dataset.type;
    // 出发地或目的地的列表
    const addressList = type + 'List';
    // 選擇的值
    let chooseData = e.detail.value;
    // 没改变的列默认会传null回来所以要转成0
    for (let i = 0; i < e.detail.value.length; i++) {
      if (chooseData[i] === null) {
        chooseData[i] = 0;
      }
    }
    // 因为picker显示的是一个长度为3的数组,对应3列,第2,3列会随着改变,所以需要保存一个当前选择的数组,才不会数据错乱
    let fixedData = Object.assign(this.data.fixedData, {
      [type]: chooseData,
      [addressList]: this.data.fixedData[addressList + 'Preview']
    })
    this.setData({
      fixedData: fixedData,
    })
    // 当改变的是出发地时,对应修改目的地的列表
    if (type === 'startSpot') {
      let lineIdTemp = this.data.fixedData['goData'][this.data.fixedData['startSpot'][0]]['children'][this.data.fixedData['startSpot'][1]]['children'] ? this.data.fixedData['goData'][this.data.fixedData['startSpot'][0]]['children'][this.data.fixedData['startSpot'][1]]['children'][this.data.fixedData['startSpot'][2]]['lineId'] : this.data.fixedData['goData'][this.data.fixedData['startSpot'][0]]['children'][this.data.fixedData['startSpot'][1]]['lineId'];
      this.getFixedRouteEndLine(lineIdTemp)
    }
  },
  // 获取目的地地址
  getFixedRouteEndLine(lineId) {
    let that = this;
    service.getConnect(service.api.getFixedRouteEndLine, {
      lineId: lineId
    }).then(function (res) {
      wx.hideLoading();
      let temp = res.data;
      let endSpotList = [];

      endSpotList.push(temp);
      endSpotList.push(temp[0]['children']);
      endSpotList.push(temp[0]['children'][0]['children'] || []);

      let fixedData = Object.assign(that.data.fixedData, {
        endSpotList: endSpotList,
        endSpotListPreview: endSpotList,
        endSpot: []
      })

      that.setData({
        fixedData: fixedData
      });
    })
  },
  // 列变化时
  bindFixedSpotPickerColumnChange(e) {
    console.log(e)
    const value = e.currentTarget.dataset.type;
    const type = e.currentTarget.dataset.type + 'Preview';
    const addressList = e.currentTarget.dataset.type + 'ListPreview'
    const data = {
      [addressList]: this.data.fixedData[addressList],
      [type]: this.data.fixedData[value].length !== 0 ? this.data.fixedData[value] : [0, 0, 0]
    }
    data[type][e.detail.column] = e.detail.value;
    if (e.detail.column === 0) {
      data[addressList][1] = data[addressList][0][e.detail.value]['children'];
      data[addressList][2] = data[addressList][1][0]['children'] || [];
      data[type][1] = 0;
      data[type][2] = 0;
    } else if (e.detail.column === 1) {
      data[addressList][2] = data[addressList][1][e.detail.value]['children'] || [];
      data[type][2] = 0;
    }
    let fixedData = Object.assign(this.data.fixedData, {
      [addressList]: data[addressList],
      [type]: data[type]
    })
    this.setData({
      fixedData: fixedData
    })
  },

  // 租车相关 ==============================================
  bindSelectTime() {
    this.setData({
      isShow: true
    })
  },

  bindSwitchChange(e){
    this.setData({
      ['rentCar.isShowToFormItem']: !this.data.rentCar.isShowToFormItem
    })
  },

  _yybindchange(e) {
    var data = e.detail
    this.setData({
      ['rentCar.beginDate']: app.utils.parseTime(new Date(data.startTime), '{y}-{m}-{d}'),
      ['rentCar.beginTime']: app.utils.parseTime(new Date(data.startTime), '{m}月{d}日'),
      ['rentCar.beginTimeDay']: app.utils.parseTime(new Date(data.startTime), '周{a}'),
      ['rentCar.endDate']: app.utils.parseTime(new Date(data.endTime), '{y}-{m}-{d}'),
      ['rentCar.endTime']: app.utils.parseTime(new Date(data.endTime), '{m}月{d}日'),
      ['rentCar.endTimeDay']: app.utils.parseTime(new Date(data.endTime), '周{a}'),
      ['rentCar.dayCount']: data.diff+1
    })
  },

  // 搜索
  bindFixedSearch() {
    if (this.data.fixedData['endSpotList'].length === 0) {
      wx.showToast({
        title: '请选择出发地，目的地~',
        icon: 'none'
      })
      return;
    }

    let lineId = null;

    let startSpotLineId = (this.data.fixedData['startSpotList'][2].length === 0 ?
      this.data.fixedData['startSpotList'][1][this.data.fixedData['startSpot'][1]]['lineId'] :
      this.data.fixedData['startSpotList'][2][this.data.fixedData['startSpot'][2]]['lineId']);
    startSpotLineId = (startSpotLineId + '').split(',');

    let endSpotLineId = (this.data.fixedData['endSpotList'][2].length === 0 ?
      this.data.fixedData['endSpotList'][1][this.data.fixedData['endSpot'][1]]['lineId'] :
      this.data.fixedData['endSpotList'][2][this.data.fixedData['endSpot'][2]]['lineId']);
    endSpotLineId = (endSpotLineId + '').split(',');

    lineId = endSpotLineId.filter(function (v) {
      return startSpotLineId.indexOf(v) !== -1 // 利用filter方法来遍历是否有相同的元素
    })

    lineId.join(',');

    if (lineId === null) {
      wx.showToast({
        title: '路线不存在，请重新选择~',
        icon: "none"
      })
      return;
    }

    wx.navigateTo({
      url: '/pages/route/fixed/timetable/timetable?lineId=' + lineId + '&chooseTime=' + this.data['date'] + '&pageName=' + this.data.Menu[this.data.menuIdx].title,
    })
  },

  // 上下滑动==================================================== 
  moveCount: 0,
  bindTouchStart(e) {
    this.moveCount = 0;
    console.log(e);
    this.setData({
      "boxY": e.changedTouches[0].pageY + this.data.move
    })
  },
  bindTouchMove(e) {
    let move = this.data.boxY - e.touches[0].pageY;

    this.moveCount++;
    console.log(this.moveCount, this.moveCount % 10)
    if (move < 0) {
      this.setData({
        move: move < 210 ? move < 0 ? 0 : move : 210
      })
    } else if (this.moveCount % 2 === 0) {
      this.setData({
        move: move < 210 ? move < 0 ? 0 : move : 210
      })
    }
  },
  bindTouchEnd(e) {
    this.moveCount = 0;
    this.setData({
      "boxY": 0
    })
  },

  // 跳转页面
  bindJumpToPage(e) {
    let page = e.currentTarget.dataset.page;
    page.url && app.jumpToPage('/' + page.url, page.title);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let sysinfo = wx.getSystemInfoSync();
    let date = new Date();
    let endDate = new Date();
    endDate.setDate(date.getDate() + 2)

    this.setData({
      btnHeight: wx.getMenuButtonBoundingClientRect().height,
      statusHeight: sysinfo.statusBarHeight,
      navHeight: sysinfo.system.indexOf('iOS') > -1 ? 44 : 48,
      ['rentCar.beginDate']: app.utils.parseTime(date, '{y}-{m}-{d}'),
      ['rentCar.beginTime']: app.utils.parseTime(date, '{m}月{d}日'),
      ['rentCar.beginTimeDay']: app.utils.parseTime(date, '周{a}'),
      ['rentCar.endDate']: app.utils.parseTime(endDate, '{y}-{m}-{d}'),
      ['rentCar.endTime']: app.utils.parseTime(endDate, '{m}月{d}日'),
      ['rentCar.endTimeDay']: app.utils.parseTime(endDate, '周{a}')
    });
    this.loadRouteHomepageData();
    this.loadAirportData();
    this.loadDailyData();
    this.loadFixedData();

    // 是否是通过分享进入
    if (options.isShowCoupon && Number(options.isShowCoupon)) {
      // 优惠券弹窗
      this.loadCouponInfo();
    }
    this.couponDialog = this.selectComponent("#coupon-dialog");
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    app.utils.initWxappStyle(app, this, this.init);
    let that = this;
    this.setData({
      mapContext: wx.createMapContext('map', this)
    });
    wx.getLocation({
      type: 'gcj02',
      success(res) {
        let latitude = res.latitude;
        let longitude = res.longitude;
        that.data.mapContext.setCenterOffset({
          offset: [0.5, 0.4]
        });
        that.data.mapContext.moveToLocation({
          latitude: latitude,
          longitude: longitude
        });
        that.setData({
          latitude: latitude,
          longitude: longitude,
          mapVisible: true
        })
      }
    })
  },

  init() {
    app.pageOnloadInit(this, app);
    this.setData({
      title: wx.getStorageSync('wxappStyle').wxappTitle || '首页'
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      userInfo: wx.getStorageSync("userInfo")
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let wxappStyle = wx.getStorageSync('wxappStyle');
    let sharePath = '/pages/index/index';
    wx.getStorageSync('token') && (sharePath = sharePath + '?token=' + wx.getStorageSync('token'));
    console.log('===================');
    console.log(sharePath);
    return {
      title: app.globalData['wxappStyle']['wxappTitle'] || wxappStyle['wxappTitle'],
      path: sharePath
    }
  },
  onShareTimeline() {}
})